package cn.itcast.controller;

import cn.itcast.domain.Standard;
import cn.itcast.service.StandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class StandardController {
    @Autowired
    private StandService standService;

    @RequestMapping("/standard_save")
    public String add(Standard standard){
        standService.add(standard);
        return "redirect:/pages/base/standard.html";
    }


    @RequestMapping("/standard_pageQuery")
    @ResponseBody
    public Map pageQuery(int page,int rows){
        Page<Standard> standards = standService.pageQuery(page, rows);
        HashMap<String, Object> result = new HashMap<>();
        result.put("total",standards.getTotalElements());
        result.put("rows",standards.getContent());
        return result;
    }
    //下拉查询
    @RequestMapping("/standard_findAll")
    @ResponseBody
    public List findAll(){
        List all = standService.findAll();
        return all;
    }


}
